package com.sy.dao.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.sy.dao.BaseDao;
import com.sy.vo.Admin;

@SuppressWarnings("unchecked")
public class AdminDaoImpl extends HibernateDaoSupport{

//日志
	protected final Log log = LogFactory.getLog(getClass());
	
	public BaseDao dao;
	
	public void addAdmin(Admin admin) {
		dao.addObject(admin);
	}

	public void deleteAdmin(Integer id) {
		dao.removeObject(Admin.class, id);
	}

	public Admin getAdmin(Integer id) {
		return (Admin)dao.getObject(Admin.class, id);
	}

	public boolean islogin(String username, String password) {
		boolean flag = false;
		Admin ad=new Admin();
		ad.setAname(username);
		ad.setApassword(password);
		List list=dao.getObjectsByExample(ad);
		if(!list.isEmpty()){
			flag=true;
		}
		return flag;
	}

	public List<Admin> listAdmins() {
		return getHibernateTemplate().find("from Admin order by aid desc");
	}

	public void updateAdmin(Admin admin) {
		dao.saveOrUpdateObject(admin);
	}

	public void setDao(BaseDao dao) {
		this.dao = dao;
	}

	public BaseDao getDao() {
		return dao;
	}

}
